package com.brandonflowers.hiveswfaddressdemo.states
{
	import com.brandonflowers.hiveswfaddressdemo.data.HiveDemoData;
	import flash.display.Shape;
	
	import org.hive.managers.plugin.LayoutManager;
	import org.hive.managers.StateManager;
	import org.hive.state.*;
	import org.hive.sequence.*;
	
	import com.brandonflowers.hiveswfaddressdemo.states.*;
	import flash.text.*;
	import flash.display.Sprite;
	
	public class AboutState extends State implements IState
	{
		private var aboutBG	:Shape;
		private var aboutTXT :TextField;
		private var aboutContainer:Sprite;
		
		public override function create():ActionSequence
		{
			//________________________________________________________________________ ASSETS
			aboutBG = new Shape();
			aboutBG.graphics.beginFill(0x0066CC);
			aboutBG.graphics.drawRect(0, 0, 400, 300);
			aboutBG.x = 0;
			aboutBG.y = 0;
						
			aboutTXT = new TextField();
			
			var format:TextFormat = new TextFormat();
			format.color = 0x0066CC;
			format.size = 30;
			format.bold = true;
			format.font = "Helvetica";
			
			aboutTXT = new TextField();
			aboutTXT.embedFonts = true;
			aboutTXT.autoSize = TextFieldAutoSize.LEFT;
			aboutTXT.antiAliasType = AntiAliasType.ADVANCED;
			aboutTXT.defaultTextFormat = format;
			aboutTXT.selectable = false;
			aboutTXT.mouseEnabled = false;
			
			aboutTXT.text = "ABOUT";
			
			aboutTXT.x = aboutBG.x;
			aboutTXT.y = aboutBG.y + aboutBG.height + 10;
			
			aboutContainer = new Sprite();
						
			aboutContainer.addChild(aboutBG);
			aboutContainer.addChild(aboutTXT);
			
			aboutContainer.alpha = 0;
			
			aboutContainer.x = 40;
			aboutContainer.y = 40;
						
			//________________________________________________________________________ SEQUENCE
			var createSequence:ActionSequence = new ActionSequence( "aboutState::createSequence" );
			createSequence.push( { scope:aboutContainer, alpha:1, time:1, transition:"easeoutsine" } );
			createSequence.push( new SequenceDelay(1000) );
			createSequence.push( { scope:aboutContainer, x:300, time:2, transition:"easeoutback" } );
			createSequence.push( new SequenceDelay(2000) );
						
			return createSequence;
		}

		private function kill():void
		{
			LayoutManager.removeChild( aboutContainer );
		}
		
		public override function close():CloseSequence
		{
			var closeSequence:CloseSequence = new CloseSequence( "aboutState::closeSequence" );
			
			closeSequence.push( {scope:aboutContainer, alpha:0, y:aboutContainer.y + 300, time:1} );
			closeSequence.push( new SequenceDelay(1000) );
			closeSequence.push( new SequenceFunction(this, kill) );
			
			return closeSequence;
		}
		
	}
	
}
